﻿<script language="c#" runat="server">
    public void Page_Load(object sender, EventArgs e)
    {
        string message = HttpContext.Current.Request.QueryString["message"];
        string name = HttpContext.Current.Request.QueryString["name"];
        string text = name + ": " + message + "(" + System.DateTime.Now.ToShortTimeString() + ")  <br>";


        if (HttpContext.Current.Cache != null)
        {
            if (HttpContext.Current.Cache["prueba"] != null)
            {
                chatContent ct = new chatContent();
                ct = (chatContent)HttpContext.Current.Cache["prueba"];


                int numElementos = ct.pila.Count;
                // si hay 10 elementos quitamos el primero de la lista...
                if (numElementos >= 10)
                {
                    ct.pila.Dequeue();
                }

                // ya podemos poner el elemento
                ct.pila.Enqueue(text);

                // grabamos los resultados...
                HttpContext.Current.Cache["prueba"] = ct;

                ct = null;
            }
            else
            {
                // lo construimos sino existe...
                chatContent ct = new chatContent();
                ct.title = "Portal 1";
                ct.pila.Enqueue(text);

                HttpContext.Current.Cache.Insert("prueba", ct, null, DateTime.Now.AddMinutes(3d), System.Web.Caching.Cache.NoSlidingExpiration);
                
               // HttpContext.Current.Cache["prueba"] = ct;
                
                ct = null;
            }


        }


    }

    //public static string ToJson(this object obj)
    //{
    //    JavaScriptSerializer js = new JavaScriptSerializer();
    //    string s = js.Serialize(obj);
    //    return s;
    //}
    //public static string ToJson(this object obj, Type type)
    //{
    //    string jsonString = string.Empty;
    //    DataContractJsonSerializer serializer = new DataContractJsonSerializer(type);
    //    using (MemoryStream ms = new MemoryStream())
    //    {
    //        serializer.WriteObject(ms, obj);
    //        jsonString = Encoding.Default.GetString(ms.ToArray());
    //    }
    //    return jsonString;
    //}
    
</script>
